//
// Created by chizuru on 2025/10/24.
//

#pragma once
#include "RegistryContainer.hpp"
#include <vector>
class TinyXmlRegisterCLBMap;
class PxdSerialAdapter;
class DeviceComm;
class CameraDevice;
class BOBCATCameraService;
class ConnectivityMonitor;
class ReconnectDecorator;
class LoggingDecorator;
namespace xclib_client {
    SINGLETON class CameraApp {
    public:
        CameraApp();
        ~CameraApp();
        // 检查特殊寄存器连接
        void ping(uint16_t unit);

        // 查询某个相机属性
        void ls(uint16_t unit);

        // 获取单个相机某个寄存器的值
        void get(uint16_t unit, const std::string& register_name);

        void set(uint16_t unit, const std::string& register_name, uint32_t val);

        void live(uint16_t unit);

        void unlive(uint16_t unit);

    private:

        struct EntryCamera{
            int unit;
            std::shared_ptr<PxdSerialAdapter> adapter;
            std::shared_ptr<LoggingDecorator> logging_wapper_adapter;
            std::shared_ptr<DeviceComm> device_comm;
            std::shared_ptr<CameraDevice> camera_device;
            std::shared_ptr<BOBCATCameraService> camera_service;
            std::shared_ptr<ConnectivityMonitor> monitor;
            std::jthread live_thread;
        };
        std::shared_ptr<TinyXmlRegisterCLBMap> reg_map;
        std::vector<std::shared_ptr<EntryCamera>> entry_cameras;
        std::unordered_map<uint16_t, std::weak_ptr<EntryCamera>> entry_map;

    };
}

